package com.wkbb.common.handler;

import com.wkbb.common.dto.HkBodyCompositionInfo;
import com.wkbb.common.dto.HkBodyShapeInfo;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class HkCompositionInfoTypeHandler extends BaseTypeHandler<HkBodyCompositionInfo> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, HkBodyCompositionInfo parameter,
									JdbcType jdbcType) throws SQLException {
		ps.setString(i, JsonUtil.objectToJson(parameter));
	}

	@Override
	public HkBodyCompositionInfo getNullableResult(ResultSet rs, String columnName)
			throws SQLException {
		String json = rs.getString(columnName);
		return JsonUtil.jsonToClass(json,HkBodyCompositionInfo.class);
	}

	@Override
	public HkBodyCompositionInfo getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		String json = rs.getString(columnIndex);
		return JsonUtil.jsonToClass(json,HkBodyCompositionInfo.class);
	}

	@Override
	public HkBodyCompositionInfo getNullableResult(CallableStatement cs, int columnIndex)
			throws SQLException {
		String json = cs.getString(columnIndex);
		return JsonUtil.jsonToClass(json,HkBodyCompositionInfo.class);
	}
}
